﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Text;
using System.Collections.Generic;
using Entity;
using BAL;
using Common;

namespace Web
{
    public partial class adminquestion : System.Web.UI.Page
    {
        private IList<QuesTypeInfo> QuesTypeInfos = new List<QuesTypeInfo>();
        private IList<SubjectInfo> SubjectInfos = new List<SubjectInfo>();
        private IList<StatusInfo> stateinfos = new List<StatusInfo>();
        private  QuestionInfo Question_Info = new QuestionInfo();
        private static UserLinkExtendInfo Uinfo = new UserLinkExtendInfo();
        protected static Module_Page Pages = new Module_Page();
        public static int PageNum = 1;
        protected static string PageState = "";
        //private static int _QuesTypeId = 0, _SubjectId = 0, _state = 0;
        //private static string _Printer = "", _Keyword = "";
        protected DateTime? _StartDate = null, _EndDate = null;
        protected string UserPopem = "";

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!UserValidate.CheckLogin(this.Request, "MasterQues"))
            {
                Response.Write("<script type=\"text/javascript\">top.location.href='login.aspx';</script>");
                Response.Redirect("login.aspx");
                Response.End();
            }
            this.UserPopem = "," + UserValidate.GetPopedom(base.Request) + ",";
            if (UserValidate.CheckLogin(this.Request, "FirstTrial"))
            {
                Question_Info.StatusId = 4;
            }
            else if (UserValidate.CheckLogin(this.Request, "FinalInstance"))
            {
                Question_Info.StatusId = 9;
            }
            if (PageValidate.QueryStringIsEmpty("page"))
            {
                Pages.PageNum = 1;
            }
            else
            {
                if (PageValidate.IsNumber(Request.QueryString["page"]))
                {
                    Pages.PageNum = int.Parse(Request.QueryString["page"]);
                }
                else
                {
                    Pages.PageNum = 1;
                }
            }
            if (!PageValidate.FormIsEmpty("StartDate"))
            {
                if (PageValidate.IsDateTime(PageValidate.Form("StartDate")))
                {
                    _StartDate = new DateTime?(DateTime.Parse(PageValidate.Form("StartDate")));
                }
                else
                {
                    this._StartDate = null;
                }
            }
            if (!PageValidate.FormIsEmpty("EndDate"))
            {
                if (PageValidate.IsDateTime(PageValidate.Form("EndDate")))
                {
                    this._EndDate = new DateTime?(DateTime.Parse(PageValidate.Form("EndDate")));
                }
                else
                {
                    this._EndDate = null;
                }
            }
            if (!PageValidate.QueryStringIsEmpty("QuesTypeId"))
            {
                if (PageValidate.IsNumber(Request.QueryString["QuesTypeId"]))
                {
                    Question_Info.QuesTypeId = int.Parse(Request.QueryString["QuesTypeId"]);
                }
                else
                {
                    Question_Info.QuesTypeId = 0;
                }
            }
            else
            {
                Question_Info.QuesTypeId = 0;
            }

            if (!PageValidate.QueryStringIsEmpty("SubjectId"))
            {
                if (PageValidate.IsNumber(Request.QueryString["SubjectId"]))
                {
                    Question_Info.SubjectId = int.Parse(Request.QueryString["SubjectId"]);
                }
                else
                {
                    Question_Info.SubjectId = 0;
                }
            }
            else
            {
                Question_Info.SubjectId = 0;
            }

            if (!PageValidate.QueryStringIsEmpty("state"))
            {
                if (PageValidate.IsNumber(Request.QueryString["state"]))
                {
                    Question_Info.StatusId = int.Parse(Request.QueryString["state"]);
                }
            }

            if (!PageValidate.QueryStringIsEmpty("CognitiveLevelId"))
            {
                if (PageValidate.IsNumber(Request.QueryString["CognitiveLevelId"]))
                {
                    Question_Info.CognitiveLevelId = int.Parse(Request.QueryString["CognitiveLevelId"]);
                }
                else
                {
                    Question_Info.CognitiveLevelId = 0;
                }
            }
            else
            {
                Question_Info.CognitiveLevelId = 0;
            }

            if (!PageValidate.QueryStringIsEmpty("DifficId"))
            {
                if (PageValidate.IsNumber(Request.QueryString["DifficId"]))
                {
                    Question_Info.DifficId = int.Parse(Request.QueryString["DifficId"]);
                }
                else
                {
                    Question_Info.DifficId = 0;
                }
            }
            else
            {
                Question_Info.DifficId = 0;
            }

            if (!PageValidate.QueryStringIsEmpty("KnowId"))
            {
                if (PageValidate.IsNumber(Request.QueryString["KnowId"]))
                {
                    Question_Info.KnowId = int.Parse(Request.QueryString["KnowId"]);
                }
                else
                {
                    Question_Info.KnowId = 0;
                }
            }
            else
            {
                Question_Info.KnowId = 0;
            }

            if (!PageValidate.QueryStringIsEmpty("ComputeTime"))
            {
                if (PageValidate.IsNumber(Request.QueryString["ComputeTime"]))
                {
                    Question_Info.ComputeTime = int.Parse(PageValidate.QueryString("ComputeTime"));
                }
                else
                {
                    Question_Info.ComputeTime = 0;
                }
            }
            else
            {
                Question_Info.ComputeTime = 0;
            }

            if (!PageValidate.QueryStringIsEmpty("BookId"))
            {
                if (PageValidate.IsNumber(Request.QueryString["BookId"]))
                {
                    Question_Info.BookId = int.Parse(Request.QueryString["BookId"]);
                }
                else
                {
                    Question_Info.BookId = 0;
                }
            }
            else
            {
                Question_Info.BookId = 0;
            }

            if (!PageValidate.QueryStringIsEmpty("Score"))
            {
                if (PageValidate.IsDecimal(Request.QueryString["Score"]))
                {
                    Question_Info.Score = decimal.Parse(Request.QueryString["Score"]);
                }
                else
                {
                    Question_Info.Score = 0;
                }
            }
            else
            {
                Question_Info.Score = 0;
            }

            if (!PageValidate.QueryStringIsEmpty("Keyword"))
            {
                Question_Info.KeyWord = Request.QueryString["Keyword"];
            }
            else
            {
                Question_Info.KeyWord = "";
            }

            if (!PageValidate.QueryStringIsEmpty("Printer"))
            {
                Question_Info.Printer = Request.QueryString["Printer"];
            }
            else
            {
                Question_Info.Printer = "";
            }
            Uinfo = UserValidate.GetInfo(this.Request);
            if (!IsPostBack)
            {
                if (!PageValidate.IsEmpty(Uinfo.SubjectList))
                {
                    IList<int> UserLinkSubjectid = ArrayHelper.ConvertToIntArray(Module_String.splitstr(Uinfo.SubjectList, ",")).ToList();
                    SubjectList.Items.Clear();
                    SubjectList.Items.Add(new ListItem("课程", "0"));
                    for (int i = 0; i < UserLinkSubjectid.Count; i++)
                    {
                       
                        LoadSubject(UserLinkSubjectid[i]);
                    }
                }
                else
                {
                    LoadSubject();
                }
                
                LoadQuesType(Uinfo.QuestionTypeList);
                LoadState();
                LoadCognitiveLevel();
                LoadDiffic();
            }
            LoadQuestionList();
        }
        //加载试题类型
        protected void lbQuestionType_DataBinding(object sender, EventArgs e)
        {
            Label lb = sender as Label;
            if (lb != null)
            {
                try
                {
                    if (lb.Text == "" || lb.Text == "0")
                    {
                        lb.Text = "";
                    }
                    QuesTypeInfo item = QuesType.GetQuesTypeInfoById(int.Parse(lb.Text));
                    if (item != null && item.Id != 0)
                    {
                        lb.Text = item.Keyword+"  "+item.Name;
                    }
                }
                catch
                {
                    lb.Text = "";
                }
            }
        }
        //加载知识点
        protected void lbKnow_DataBinding(object sender, EventArgs e)
        {
            Label lb = sender as Label;
            if (lb != null)
            {
                try
                {
                    if (lb.Text == "" || lb.Text == "0")
                    {
                        lb.Text = "";
                    }
                    else
                    {

                        KnowledgeInfo item = Knowledge.GetKnowledgeInfoById(int.Parse(lb.Text));
                        if (item != null && item.Id != 0)
                        {
                            lb.Text = item.Keyword + "&nbsp;&nbsp;" + item.Name;
                        }
                    }
                }
                catch
                {
                    lb.Text = "";
                }
            }
        }
        //加载难度级别
        protected void lbDiff_DataBinding(object sender, EventArgs e)
        {
            Label lb = sender as Label;
            if (lb != null)
            {
                try
                {
                    if (lb.Text == "" || lb.Text == "0")
                    {
                        lb.Text = "";
                    }
                    else
                    {
                        DifficInfo item = Diffic.GetDifficInfoById(int.Parse(lb.Text));
                        if (item != null && item.Id != 0)
                        {
                            lb.Text = item.Keyword+"  "+item.Name;
                        }
                    }
                }
                catch
                {
                    lb.Text = "";
                }
            }
        }

        //加载认知层次
        protected void lbCog_DataBinding(object sender, EventArgs e)
        {
            Label lb = sender as Label;
            if (lb != null)
            {
                try
                {
                    if (lb.Text == "" || lb.Text == "0")
                    {
                        lb.Text = "";
                    }
                    else
                    {
                        //DifficInfo item = Diffic.GetDifficInfoById(int.Parse(lb.Text));
                        CognitiveLevelInfo item = CognitiveLevel.GetT1(int.Parse(lb.Text)); 
                        if (item != null && item.Id != 0)
                        {
                            lb.Text = item.Keyword+"  "+item.Name;
                        }
                    }
                }
                catch
                {
                    lb.Text = "";
                }
            }
        }

        private void LoadQuestionList()
        {
            IList<int> UserIds = Users.GetUserIds(Uinfo.RoleList);
            string UIds = "";
            if (UserIds.Count > 0)
            {
                UIds = string.Join(",", ArrayHelper.ConvertToStringArray(GetArray<int>.Get(UserIds)));
            }
            Pages.AllCount = Question.GetQuestionCount(Question_Info, Uinfo.QuestionTypeList, Uinfo.SubjectList, UIds, _StartDate, _EndDate);
            Pages.PageSize = 10;
            Pages.PageName = GetPageFileName(0);
            Pages.Compute();
            PageLabel.Text = Pages.GetPage();
            QList.DataSource = Question.GetQuestionInfofs(Question_Info, Uinfo.QuestionTypeList, Uinfo.SubjectList, UIds, _StartDate, _EndDate, Pages.First, Pages.Max);
            QList.DataBind();
            this.SetFormState();
        }

        protected void LoadDiffic()
        {
            IList<DifficInfo> Difficinfos = Diffic.GetDifficInfos(0, 0);
            DifficIdList.Items.Clear();
            DifficIdList.Items.Add(new ListItem("请选择难度级别", "0"));
            foreach (DifficInfo info in Difficinfos)
            {
                DifficIdList.Items.Add(new ListItem(info.Name+"    " + info.Keyword.ToString(), info.Keyword.ToString()));
            }
        }

        protected void LoadQuesType(string IdList)
        {
            QuesTypeInfos = QuesType.GetQuesTypeInfos(0, 0);
            if (!PageValidate.IsEmpty(IdList))
            {
                QuesTypeInfos = QuesTypeInfos.Where(t => ArrayHelper.ConvertToIntArray(Module_String.splitstr(IdList, ",")).Contains(t.Id)).ToList();
            }
            QuesTypeList.Items.Clear();
            QuesTypeList.Items.Add(new ListItem("试题类型", "0"));
            foreach (QuesTypeInfo info in QuesTypeInfos)
            {
                QuesTypeList.Items.Add(new ListItem(info.Name + "    " + info.Keyword.ToString(), info.Keyword.ToString()));
            }
        }

        protected void LoadSubject()
        {
            SubjectInfos = Subject.GetSubjectInfos();
            SubjectList.Items.Clear();
            SubjectList.Items.Add(new ListItem("课程", "0"));
            foreach (SubjectInfo info in SubjectInfos)
            {
                SubjectList.Items.Add(new ListItem(info.Name, info.Id.ToString()));//+"    "+info.Keyword.ToString()
            }
        }
        //专家加载课程
        protected void LoadSubject(int subjectId)
        {
            SubjectInfos = Subject.GetSubjectInfoszhuangjiang(subjectId);
            //SubjectList.Items.Clear();
           // SubjectList.Items.Add(new ListItem("课程", "0"));
            foreach (SubjectInfo info in SubjectInfos)
            {
                SubjectList.Items.Add(new ListItem(info.Name, info.Id.ToString()));//+"    "+info.Keyword.ToString()
            }
        }

        protected void LoadState()
        {
            stateinfos = Status.GetStatusInfos(0, 0);
            StateList.Items.Clear();
            StateList.Items.Add(new ListItem("审核状态", "0"));
            foreach (StatusInfo info in stateinfos)
            {
                StateList.Items.Add(new ListItem(info.Name, info.Id.ToString()));
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            //是搜索的数据的默认为第一页显示
            Pages.PageNum = 1;
            int quesTypeid = 0;
            if (QuesTypeList.SelectedValue!="0")
            {
                quesTypeid = QuesType.GetQuesTypeIdByKeyword(QuesTypeList.SelectedValue);
            }
            Question_Info.QuesTypeId = quesTypeid;
            Question_Info.SubjectId = int.Parse(SubjectList.SelectedValue);
            Question_Info.KeyWord = KeyWord.Text.Trim();
            Question_Info.Printer = Printer.Text.Trim();
            Question_Info.StatusId = int.Parse(StateList.SelectedValue);
            int difficid = 0;//难度级别
            if (DifficIdList.SelectedValue != "0")
            {
                difficid = Diffic.GetDifficIDByKeyword(DifficIdList.SelectedValue);//通过关键字查询难度级别的编号
            }
            
            Question_Info.DifficId =difficid;
            int cognitiveLevelid =0;//认知层次
            if (CognitiveLevelIdList.SelectedValue!="0")
            {
                cognitiveLevelid = CognitiveLevel.GetCognitiveLevelIDByKeyword(CognitiveLevelIdList.SelectedValue);//通过关键字查询认知层次的id ;
            }
            Question_Info.CognitiveLevelId = cognitiveLevelid;
            if (BookList.SelectedValue.Trim() != "")
            {
                Question_Info.BookId = int.Parse(BookList.SelectedValue);
            }
            else
            {
                Question_Info.BookId = 0;
            }

            if (KnowIdList.SelectedValue.Trim() != "")
            {
                int knowId = 0;//知识点
                if (KnowIdList.SelectedValue != "0")
                {
                    knowId = Knowledge.GetKnowledgeIDByKeyword(KnowIdList.SelectedValue, Convert.ToInt32(SubjectList.SelectedValue));//通过关键字查询知识点的id
                }
                Question_Info.KnowId = knowId;
            }
            else
            {
                Question_Info.KnowId = 0;
            }

            if (Score.Text.Trim() != null && Score.Text.Trim() != "")
            {
                try
                {

                    Double aa = Convert.ToDouble(Score.Text.Trim());
                    if (aa <= 0 || aa > 60)
                    {
                        Utility.ShowBoxyAlert("查询的分数必须在（0.5~60）范围内", this);
                        return;
                    }
                }
                catch (Exception ex)
                {
                    Utility.ShowBoxyAlert("查询的分数必须是数字", this);
                    return;
                }
            }
            if (PageValidate.IsDecimal(Score.Text.Trim()))
            {
                Question_Info.Score = decimal.Parse(Score.Text.Trim());
            }
            else
            {
                Question_Info.Score = 0;
            }
            if (PageValidate.IsDateTime(this.StartDate.Text.Trim()))
            {
                this._StartDate = new DateTime?(DateTime.Parse(this.StartDate.Text.Trim()));
            }
            if (PageValidate.IsDateTime(this.EndDate.Text.Trim()))
            {
                this._EndDate = new DateTime?(DateTime.Parse(this.EndDate.Text.Trim()));
            }
            if (ComputeTime.Text.Trim() != null && ComputeTime.Text.Trim() != "")
            {
                try
                {
                    Convert.ToDouble(ComputeTime.Text.Trim());
                }
                catch (Exception ex)
                {
                    Utility.ShowBoxyAlert("查询的时间必须是数字", this);
                    return;
                }

                if (Convert.ToDouble(ComputeTime.Text.Trim()) <= 0 || Convert.ToDouble(ComputeTime.Text.Trim()) > 5400)
                {
                    Utility.ShowBoxyAlert("查询的时间必须在（0~5400）范围内", this);
                    return;
                }
                else if (PageValidate.IsNumber(ComputeTime.Text.Trim()))
                {
                    Question_Info.ComputeTime = int.Parse(ComputeTime.Text.Trim());
                }
                else
                {
                    Question_Info.ComputeTime = 0;
                }
            }
            LoadQuestionList();
        }

        protected void LoadBook(int inputSubjectId)
        {
            IList<BookInfo> BookInfos = Book.GetBookInfosBySubject(inputSubjectId, 0, 0);
            BookList.Items.Clear();
            BookList.Items.Add(new ListItem("请选择适用范围", "0"));
            foreach (BookInfo info in BookInfos)
            {
                BookList.Items.Add(new ListItem(info.Name.ToString(), info.Id.ToString()));//+"    "+info.Keyword.ToString()
            }
        }

        protected void LoadCognitiveLevel()
        {
            IList<CognitiveLevelInfo>  CognitiveLevelInfos = CognitiveLevel.GetList(0);
            CognitiveLevelIdList.Items.Clear();
            CognitiveLevelIdList.Items.Add(new ListItem("请选择认知层次", "0"));
            foreach (CognitiveLevelInfo info in CognitiveLevelInfos)
            {
                CognitiveLevelIdList.Items.Add(new ListItem(info.Name+"    "+info.Keyword.ToString(), info.Keyword.ToString()));
            }
        }

        protected void LoadKnowledge(int ParentID, int inputSubjectId, string line)
        {


            if (ParentID == 0)
            {
                KnowIdList.Items.Clear();
                KnowIdList.Items.Add(new ListItem("请选择知识点", "0"));
                IList<KnowledgeInfo> knowledgeInfos = Knowledge.GetRootKnowledgeInfo(0, inputSubjectId);
                foreach (KnowledgeInfo info in knowledgeInfos)
                {
                    ListItem item = new ListItem(info.Keyword + "  " + info.Name, info.Keyword);//+ "    " + info.Keyword
                    KnowIdList.Items.Add(item);
                    item = new ListItem(info.Keyword, info.Keyword);
                    LoadKnowledge(info.Id, inputSubjectId, "|——");
                }
            }
            else
            {
                IList<KnowledgeInfo> knowledgeInfos = Knowledge.GetKnowledgeInfos(ParentID);//通过parentId获取子集合
                foreach (KnowledgeInfo info in knowledgeInfos)
                {
                    ListItem item = new ListItem(line + info.Keyword + "  " + info.Name, info.Keyword);//+ "    " + info.Keyword
                    KnowIdList.Items.Add(item);
                    item = new ListItem(line + info.Keyword, info.Keyword);
                    LoadKnowledge(info.Id, inputSubjectId, "|——" + line);
                }
            }
        }

        #region 旧的代码测试没有问题时可删除
        //protected void LoadQuestion(QuestionInfo inputQuestionInfo)
        //{

        //    int AllCount = Question.GetQuestionCount(inputQuestionInfo);

        //    int PageSize = 10, PageCount = 0, LastPageCount = 0, tFirst = 1, tMax = 0;
        //    if (AllCount == 0)
        //    {
        //        QList.Items.Clear();
        //        QList.DataBind();
        //        PageLabel.Text = "";
        //        return;
        //    }
        //    else if (AllCount % PageSize > 0)
        //    {
        //        PageCount = AllCount / PageSize + 1;
        //        LastPageCount = AllCount % PageSize;
        //    }
        //    else
        //    {
        //        PageCount = AllCount / PageSize;
        //        LastPageCount = PageSize;
        //    }

        //    if (PageNum > LastPageCount && AllCount == 0 && PageCount == 0 && LastPageCount == 0)
        //    {
        //        return ;
        //    }

        //    //如果数据总数小于每页数量且页码>1，则返回空，否则返回全部数据作为第一页。
        //    if (AllCount < PageSize)
        //    {
        //        if (PageNum > 1)
        //        {
        //            tFirst = 0;
        //            tMax = AllCount;
        //        }
        //    }
        //    else if ((PageNum * PageSize) > AllCount)//如果要取得数据超过了数据范围一页的数量，则返回一个Null，否则返回最后一页数据
        //    {
        //        tFirst = AllCount - LastPageCount;
        //        tMax = LastPageCount;
        //    }
        //    else//计算分页数据
        //    {
        //        tFirst = (PageNum - 1) * PageSize;
        //        tMax = PageSize;
        //    }

        //    QList.DataSource = Question.GetQuestionInfofs(inputQuestionInfo, tFirst, tMax);
        //    QList.DataBind();
        //    string _PageName = GetPageFileName(0);
        //    StringBuilder sb = new StringBuilder();
        //    sb.Append("<div id='page'>共有 ");
        //    sb.Append(AllCount.ToString());
        //    sb.Append(" 条记录 | 分 ");
        //    sb.Append(PageCount.ToString());
        //    sb.Append(" 页 | 当前为：");
        //    sb.Append(PageNum.ToString());
        //    sb.Append(" 分页：<a href='");
        //    sb.Append(_PageName);
        //    sb.Append("1'>首页</a>");
        //    if (PageNum == 1)
        //    {
        //        sb.Append(" | 上一页");
        //    }
        //    else
        //    {
        //        sb.Append(" | <a href='");
        //        sb.Append(_PageName);
        //        sb.Append((PageNum - 1).ToString());
        //        sb.Append("'>上一页</a>");
        //    }

        //    if (PageNum == PageCount)
        //    {
        //        sb.Append(" | 下一页");
        //    }
        //    else
        //    {
        //        sb.Append("| <a href='");
        //        sb.Append(_PageName);
        //        sb.Append((PageNum + 1).ToString());
        //        sb.Append("'>下一页</a>");
        //    }
        //    sb.Append(" | <a href='");
        //    sb.Append(_PageName);
        //    sb.Append(PageCount.ToString());
        //    sb.Append("'>末页</a>");
        //    sb.Append(" | <a href='javascript://' id='PageGo'>跳转</a>：<input id='pc' name='pc' type='text' value='");
        //    sb.Append(PageNum.ToString());
        //    sb.Append("' size='1' />");
        //    sb.Append("</div>");
        //    sb.Append("\r\n<script>\r\n$(function(){$(\"#PageGo\").click(function(){location.href=\"");
        //    sb.Append(_PageName);
        //    sb.Append("\"+$(\"#pc\").val()});});\r\n</script>\r\n");

        //    PageLabel.Text = sb.ToString();
        //}

        //protected void LoadQuestion(QuestionInfo inputQuestionInfo,List<int> subjects,int count)
        //{

        //    int AllCount = count;//总共数据数量 Question.GetQuestionCount(inputQuestionInfo);

        //    int PageSize = 10, PageCount = 0, LastPageCount = 0, tFirst = 1, tMax = 0;
        //    if (AllCount == 0)
        //    {
        //        QList.Items.Clear();
        //        QList.DataBind();
        //        PageLabel.Text = "";
        //        return;
        //    }
        //    else if (AllCount % PageSize > 0)
        //    {
        //        PageCount = AllCount / PageSize + 1;
        //        LastPageCount = AllCount % PageSize;
        //    }
        //    else
        //    {
        //        PageCount = AllCount / PageSize;
        //        LastPageCount = PageSize;
        //    }

        //    if (PageNum > LastPageCount && AllCount == 0 && PageCount == 0 && LastPageCount == 0)
        //    {
        //        return;
        //    }

        //    //如果数据总数小于每页数量且页码>1，则返回空，否则返回全部数据作为第一页。
        //    if (AllCount < PageSize)
        //    {
        //        if (PageNum > 1)
        //        {
        //            tFirst = 0;
        //            tMax = AllCount;
        //        }
        //    }
        //    else if ((PageNum * PageSize) > AllCount)//如果要取得数据超过了数据范围一页的数量，则返回一个Null，否则返回最后一页数据
        //    {
        //        tFirst = AllCount - LastPageCount;
        //        tMax = LastPageCount;
        //    }
        //    else//计算分页数据
        //    {
        //        tFirst = (PageNum - 1) * PageSize;
        //        tMax = PageSize;
        //    }
        //    /*List<QuestionInfo> questionList =new List<QuestionInfo>();
        //    for (int i = 0; i < subjects.Count;i++ )
        //    {
        //        inputQuestionInfo.SubjectId = subjects[i];
        //        IList<QuestionInfo> tempQuestionList = Question.GetQuestionInfofs(inputQuestionInfo, tFirst, tMax);
        //        for (int j = 0; j <tempQuestionList.Count;j++ )
        //        {
        //            questionList.Add(tempQuestionList[i]);
        //        }
        //    }*/


        //   // QList.DataSource =questionList; //Question.GetQuestionInfofs(inputQuestionInfo, tFirst, tMax);
        //    //QList .DataSource=Question.GetQuestionInfofs(inputQuestionInfo, tFirst, tMax,subjects);
        //    QList.DataBind();
        //    string _PageName = GetPageFileName(0);
        //    StringBuilder sb = new StringBuilder();
        //    sb.Append("<div id='page'>共有 ");
        //    sb.Append(AllCount.ToString());
        //    sb.Append(" 条记录 | 分 ");
        //    sb.Append(PageCount.ToString());
        //    sb.Append(" 页 | 当前为：");
        //    sb.Append(PageNum.ToString());
        //    sb.Append(" 分页：<a href='");
        //    sb.Append(_PageName);
        //    sb.Append("1'>首页</a>");
        //    if (PageNum == 1)
        //    {
        //        sb.Append(" | 上一页");
        //    }
        //    else
        //    {
        //        sb.Append(" | <a href='");
        //        sb.Append(_PageName);
        //        sb.Append((PageNum - 1).ToString());
        //        sb.Append("'>上一页</a>");
        //    }

        //    if (PageNum == PageCount)
        //    {
        //        sb.Append(" | 下一页");
        //    }
        //    else
        //    {
        //        sb.Append("| <a href='");
        //        sb.Append(_PageName);
        //        sb.Append((PageNum + 1).ToString());
        //        sb.Append("'>下一页</a>");
        //    }
        //    sb.Append(" | <a href='");
        //    sb.Append(_PageName);
        //    sb.Append(PageCount.ToString());
        //    sb.Append("'>末页</a>");
        //    sb.Append(" | <a href='javascript://' id='PageGo'>跳转</a>：<input id='pc' name='pc' type='text' value='");
        //    sb.Append(PageNum.ToString());
        //    sb.Append("' size='1' />");
        //    sb.Append("</div>");
        //    sb.Append("\r\n<script>\r\n$(function(){$(\"#PageGo\").click(function(){location.href=\"");
        //    sb.Append(_PageName);
        //    sb.Append("\"+$(\"#pc\").val()});});\r\n</script>\r\n");

        //    PageLabel.Text = sb.ToString();
        //}
        ////限制条件下的分页数量限制
        //protected void LoadQuestionLimit(int AllCount,List<int> subjectids) 
        //{
        //    int PageSize = 10, PageCount = 0, LastPageCount = 0, tFirst = 1, tMax = 0;
        //    if (AllCount == 0)
        //    {
        //        QList.Items.Clear();
        //        QList.DataBind();
        //        PageLabel.Text = "";
        //        return;
        //    }
        //    else if (AllCount % PageSize > 0)
        //    {
        //        PageCount = AllCount / PageSize + 1;
        //        LastPageCount = AllCount % PageSize;
        //    }
        //    else
        //    {
        //        PageCount = AllCount / PageSize;
        //        LastPageCount = PageSize;
        //    }

        //    if (PageNum > LastPageCount && AllCount == 0 && PageCount == 0 && LastPageCount == 0)
        //    {
        //        return;
        //    }

        //    //如果数据总数小于每页数量且页码>1，则返回空，否则返回全部数据作为第一页。
        //    if (AllCount < PageSize)
        //    {
        //        if (PageNum > 1)
        //        {
        //            tFirst = 0;
        //            tMax = AllCount;
        //        }
        //    }
        //    else if ((PageNum * PageSize) > AllCount)//如果要取得数据超过了数据范围一页的数量，则返回一个Null，否则返回最后一页数据
        //    {
        //        tFirst = AllCount - LastPageCount;
        //        tMax = LastPageCount;
        //    }
        //    else//计算分页数据
        //    {
        //        tFirst = (PageNum - 1) * PageSize;
        //        tMax = PageSize;
        //    }



        //    QList.DataSource = Question.getQuestionListBySubject(subjectids, tFirst, tMax);
        //    QList.DataBind();
        //    string _PageName = GetPageFileName(0);
        //    StringBuilder sb = new StringBuilder();
        //    sb.Append("<div id='page'>共有 ");
        //    sb.Append(AllCount.ToString());
        //    sb.Append(" 条记录 | 分 ");
        //    sb.Append(PageCount.ToString());
        //    sb.Append(" 页 | 当前为：");
        //    sb.Append(PageNum.ToString());
        //    sb.Append(" 分页：<a href='");
        //    sb.Append(_PageName);
        //    sb.Append("1'>首页</a>");
        //    if (PageNum == 1)
        //    {
        //        sb.Append(" | 上一页");
        //    }
        //    else
        //    {
        //        sb.Append(" | <a href='");
        //        sb.Append(_PageName);
        //        sb.Append((PageNum - 1).ToString());
        //        sb.Append("'>上一页</a>");
        //    }

        //    if (PageNum == PageCount)
        //    {
        //        sb.Append(" | 下一页");
        //    }
        //    else
        //    {
        //        sb.Append("| <a href='");
        //        sb.Append(_PageName);
        //        sb.Append((PageNum + 1).ToString());
        //        sb.Append("'>下一页</a>");
        //    }
        //    sb.Append(" | <a href='");
        //    sb.Append(_PageName);
        //    sb.Append(PageCount.ToString());
        //    sb.Append("'>末页</a>");
        //    sb.Append(" | <a href='javascript://' id='PageGo'>跳转</a>：<input id='pc' name='pc' type='text' value='");
        //    sb.Append(PageNum.ToString());
        //    sb.Append("' size='1' />");
        //    sb.Append("</div>");
        //    sb.Append("\r\n<script>\r\n$(function(){$(\"#PageGo\").click(function(){location.href=\"");
        //    sb.Append(_PageName);
        //    sb.Append("\"+$(\"#pc\").val()});});\r\n</script>\r\n");

        //    PageLabel.Text = sb.ToString();
        //} 
        #endregion

        protected string GetPageFileName(int page)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("adminquestion.aspx?");
            if (Question_Info.QuesTypeId > 0)
            {
                sb.Append("QuesTypeId=");
                sb.Append(Question_Info.QuesTypeId);
                sb.Append("&");
            }
            if (Question_Info.SubjectId > 0)
            {
                sb.Append("SubjectId=");
                sb.Append(Question_Info.SubjectId);
                sb.Append("&");
            }
            if (Question_Info.KeyWord != "")
            {
                sb.Append("Keyword=");
                sb.Append(Question_Info.KeyWord);
                sb.Append("&");
            }
            if (Question_Info.Printer != "")
            {
                sb.Append("Printer=");
                sb.Append(Question_Info.Printer);
                sb.Append("&");
            }
            if (Question_Info.ComputeTime > 0)
            {
                sb.Append("ComputeTime=");
                sb.Append(Question_Info.ComputeTime);
                sb.Append("&");
            }
            if (Question_Info.CognitiveLevelId > 0)
            {
                sb.Append("CognitiveLevelId=");
                sb.Append(Question_Info.CognitiveLevelId);
                sb.Append("&");
            }
            if (Question_Info.DifficId > 0)
            {
                sb.Append("DifficId=");
                sb.Append(Question_Info.DifficId);
                sb.Append("&");
            }
            if (Question_Info.BookId > 0)
            {
                sb.Append("BookId=");
                sb.Append(Question_Info.BookId);
                sb.Append("&");
            }
            if (Question_Info.Score > 0)
            {
                if (Question_Info.Score > 0)
                {
                    sb.Append("Score=");
                    sb.Append(Question_Info.Score);
                    sb.Append("&");
                }
            }
            if (Question_Info.KnowId > 0)
            {
                if (Question_Info.KnowId > 0)
                {
                    sb.Append("KnowId=");
                    sb.Append(Question_Info.KnowId);
                    sb.Append("&");
                }
            }
            if (Question_Info.StatusId > 0)
            {
                sb.Append("state=");
                sb.Append(Question_Info.StatusId);
                sb.Append("&");
            }
            else
            {
                sb.Append("state=0&");
            }
            if (PageValidate.IsDateTime(_StartDate.ToString()))
            {
                sb.Append("StartDate=");
                sb.Append(this._StartDate);
                sb.Append("&");
            }
            if (PageValidate.IsDateTime(_EndDate.ToString()))
            {
                sb.Append("EndDate=");
                sb.Append(this._EndDate);
                sb.Append("&");
            }
            sb.Append("page=");
            if (page > 0)
            {
                sb.Append(page);
            }
            string t = sb.ToString();
            PageState = Common.DESEncrypt.Encrypt(t+Pages.PageNum);
            return t;
        }

        /// <summary>
        /// 取得状态标题
        /// </summary>
        /// <param name="Statusid"></param>
        /// <returns></returns>
        public string GetStatusName(object Statusid)
        {
            int t = Convert.ToInt32(Statusid);
            return Status.GetStatusInfoById(t).Name;
        }

        protected void SetSubjectId(int inputSubjectId)
        {
            LoadKnowledge(0, inputSubjectId, "——");
            LoadBook(inputSubjectId);
            if (Question_Info.SubjectId > 0 && Question_Info.BookId > 0)
            {
                BookList.SelectedValue = Question_Info.BookId.ToString();
            }
            BookList.Visible = true;
            KnowIdList.Visible = true;
        }

        protected void SetFormState()
        {
            if (Question_Info.SubjectId > 0)
            {
                StateList.SelectedValue = Question_Info.StatusId.ToString();
            }
            if (Question_Info.SubjectId > 0)
            {
                SubjectList.SelectedValue = Question_Info.SubjectId.ToString();
                SetSubjectId(Question_Info.SubjectId);
            }
            if (!PageValidate.IsEmpty(StartDate.Text))
            {
                StartDate.Text = _StartDate.ToString();
            }
            if (!PageValidate.IsEmpty(EndDate.Text))
            {
                EndDate.Text = _EndDate.ToString();
            }
            if (Question_Info.ComputeTime > 0)
            {
                ComputeTime.Text = Question_Info.ComputeTime.ToString();
            }
            if (Question_Info.Score > 0)
            {
                Score.Text = Question_Info.Score.ToString();
            }
            if (!PageValidate.IsEmpty(Question_Info.Printer))
            {
                Printer.Text = Question_Info.Printer;
            }
            if (!PageValidate.IsEmpty(Question_Info.KeyWord))
            {
                KeyWord.Text = Question_Info.KeyWord;
            }
            if (Question_Info.DifficId > 0)
            {
                DifficIdList.SelectedValue = Diffic.GetDifficInfoById(Question_Info.DifficId).Keyword;
            }
            if (Question_Info.CognitiveLevelId > 0)
            {
                CognitiveLevelIdList.SelectedValue = CognitiveLevel.GetSingleInfo(Question_Info.CognitiveLevelId).Keyword;
            }
        }
        protected void SubjectIdList_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (SubjectList.SelectedIndex > -1)
            {
                int tSubjectId = int.Parse(SubjectList.SelectedValue.Trim());
                SetSubjectId(tSubjectId);
            }
        }
    }
}
